// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2024 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
package sys

import (
	"context"
	"hotgo/addons/hgexample/api/admin/eporder"
	"hotgo/addons/hgexample/model/input/sysin"
	"hotgo/addons/hgexample/service"
)

var (
	EpOrder = cEpOrder{}
)

type cEpOrder struct{}

// List 查看订单列表
func (c *cEpOrder) List(ctx context.Context, req *eporder.ListReq) (res *eporder.ListRes, err error) {
	list, totalCount, err := service.SysEpOrder().List(ctx, &req.EpOrderListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*sysin.EpOrderListModel{}
	}

	res = new(eporder.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Export 导出订单列表
func (c *cEpOrder) Export(ctx context.Context, req *eporder.ExportReq) (res *eporder.ExportRes, err error) {
	err = service.SysEpOrder().Export(ctx, &req.EpOrderListInp)
	return
}

// Edit 更新订单
func (c *cEpOrder) Edit(ctx context.Context, req *eporder.EditReq) (res *eporder.EditRes, err error) {
	err = service.SysEpOrder().Edit(ctx, &req.EpOrderEditInp)
	return
}

// MaxSort 获取订单最大排序
func (c *cEpOrder) MaxSort(ctx context.Context, req *eporder.MaxSortReq) (res *eporder.MaxSortRes, err error) {
	data, err := service.SysEpOrder().MaxSort(ctx, &req.EpOrderMaxSortInp)
	if err != nil {
		return
	}

	res = new(eporder.MaxSortRes)
	res.EpOrderMaxSortModel = data
	return
}

// View 获取指定订单信息
func (c *cEpOrder) View(ctx context.Context, req *eporder.ViewReq) (res *eporder.ViewRes, err error) {
	data, err := service.SysEpOrder().View(ctx, &req.EpOrderViewInp)
	if err != nil {
		return
	}

	res = new(eporder.ViewRes)
	res.EpOrderViewModel = data
	return
}

// Delete 删除订单
func (c *cEpOrder) Delete(ctx context.Context, req *eporder.DeleteReq) (res *eporder.DeleteRes, err error) {
	err = service.SysEpOrder().Delete(ctx, &req.EpOrderDeleteInp)
	return
}

// Status 更新订单状态
func (c *cEpOrder) Status(ctx context.Context, req *eporder.StatusReq) (res *eporder.StatusRes, err error) {
	err = service.SysEpOrder().Status(ctx, &req.EpOrderStatusInp)
	return
}